package com.cvai.controller;

import com.cvai.R.Result;
import com.cvai.context.BaseContext;
import com.cvai.domain.po.Memory;
import com.cvai.service.IMemoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/memory")
@RequiredArgsConstructor
@CrossOrigin
public class MemoryController {
    private final IMemoryService memoryService;
    @GetMapping
    public Result<String> getMemory() {
        log.info("获取memoryId");
        String id = UUID.randomUUID().toString();
        Memory memory = new Memory();
        if(BaseContext.getCurrentUser()!=null){
            memory.setUserId(BaseContext.getCurrentUser().getId());
        }
        memory.setId(id);
        memoryService.save(memory);
        return Result.success(id);
    }
}
